<h1>
   Next, Select a Doctor
</h1>


<?php

function datePlus($dateDo) {
    date_default_timezone_set('UTC');
    $timeStamp = strtotime($dateDo);
    $timeStamp += 24 * 60 * 60;
    $newDate = date("Y-m-d", $timeStamp);
    return $newDate;
}

function dateMoins($dateDo) {
    date_default_timezone_set('UTC');
    $timeStamp = strtotime($dateDo);
    $timeStamp -= 24 * 60 * 60;
    $newDate = date("Y-m-d", $timeStamp);
    return $newDate;
}

$dateplus = datePlus($this->date);
$datemoins = dateMoins($this->date);
$doctors = $this->doctors;
$patient = $this->patient->PatientId;
$pdoc = $this->pdoc;
//echo "pdoc is: " . print_r($pdoc);

?>

<div id="date_affiche"> <a href="<?php echo $this->url(array('controller' => 'appointment',
    'action' => 'doctorappointment', 'date' => $datemoins)); ?>">&lt;--</a>
                                  <?php echo $this->date; ?>
    <a href="<?php echo $this->url(array('controller' => 'appointment',
                                      'action' => 'doctorappointment', 'date' => $dateplus)); ?>">--&gt;</a>
 </div>
 
<div><br/></div>

<?php

	if($pdoc != NULL){
?>

<h2><?php echo "Preferred Doctor (". $pdoc->FName . " " . $pdoc->LName .") Availability for " . $this->date ?></h2>
<table>
	
 

  	<tr>
                             
                          
                                      <th>8am</th>
                                      <th>9am</th>
                                      <th>10am</th>
                                      <th>11am</th>
                                      <th>12pm</th>
                                      <th>1pm</th>
                                      <th>2pm</th>
                                      <th>3pm</th>
                                      <th>4pm</th>
                                      <th>5pm</th>
                                      <th>6pm</th>
                                      <th>7pm</th>
                                      <th>8pm</th>
                                      <th>9pm</th>
                                      <th>10pm</th>
                                      <th>11pm</th>
                              
         
                                  </tr>

                                          <tr>
                                             
        <?php for ($j = 8; $j < 24; $j++) {
 ?>
                                              <td>
            <?php
                                              if ($this->tab[$pdoc->UserId][$j] == null) { ?>
                                                  <a href="<?php echo $this->url(array('controller' => 'appointment',
                           'action' => 'roomappointment', 'doctorid' => $pdoc->UserId, 'hour'=>$j)); ?>">Free</a>

                                                  
                                              <?php } else {
                                                  echo 'Booked';
                                              }
            ?>
                                              </td>
    <?php } ?>
                                          </tr>

                                  </table>

<?php
} // end if
?>
<h2>All Doctors:</h3>

<table>
    	<tr>
                             		  <th>Doctor ID</th>
                             		  <th>Doctor Name</th>
                                     
                                      <th>8am</th>
                                      <th>9am</th>
                                      <th>10am</th>
                                      <th>11am</th>
                                      <th>12pm</th>
                                      <th>1pm</th>
                                      <th>2pm</th>
                                      <th>3pm</th>
                                      <th>4pm</th>
                                      <th>5pm</th>
                                      <th>6pm</th>
                                      <th>7pm</th>
                                      <th>8pm</th>
                                      <th>9pm</th>
                                      <th>10pm</th>
                                      <th>11pm</th>
                              
         
                                  </tr>
   
    <?php foreach ($this->allusers as $a) : 
    	if (strcmp(strtoupper($a->UserType),"DOCTOR") == 0){?>
        
                                          <tr>
                                          	<td><?php echo $a->UserId; ?></td>
                                          	<td><?php echo $a->LName . " " . $a->FName;?></td>
                                             
        <?php for ($j = 8; $j < 24; $j++) {
 ?>
                                              <td>
            <?php
                                              if ($this->tab[$a->UserId][$j] == null) { ?>
                                                  <a href="<?php echo $this->url(array('controller' => 'appointment',
                           'action' => 'roomappointment', 'doctorid' => $a->UserId, 'hour'=>$j)); ?>">Free</a>
												
                                                  
                                              <?php } //end if
                                              else {
                                                  echo 'Booked';
                                              } //end else
            ?>
                                              </td>
    <?php }  //end for ?>
                                          </tr>
        
        
        
     
    <?php  } //end if 
    endforeach; //end for each ?>
</table>

<div id="Recherche">
<?php echo $this->form ;?>
</div>